package com.fingard.dsp.bank.reqrespobj.batrecrefund;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.batrecrefund.detail.RetAtsBatRecRefundDetail;
import com.fingard.xml.XmlTextWriter;

public class RetAtsQryBatRecRefund extends RetAtsBase {
	public String respCode;
	public String respInfo;
	public String reqSeqID;
	public String transState;
	public String payInfoCode;

	public RetAtsQryBatRecRefund(ReqRespHeader p_header) {
		retHeader = p_header;
		retXmlWriter = new XmlTextWriter();
	}

	private int writeRdCount = 0;
	public int getWrittenRdCount(){
		return writeRdCount;
	}
	
	private RetAtsBatRecRefundDetail tmpRetDetail = null;
	public void writeRetDetail(RetAtsBatRecRefundDetail p_retDetail) throws Exception {
		if (tmpRetDetail == null) {
			tmpRetDetail = p_retDetail;
		}
		writeRdCount++;
		if (!hasWrittenBefore) {
			writeBeforeDetail();
		}
		retXmlWriter.writeStartElement("DetailRecord");
		retXmlWriter.writeElementString("PostScript", p_retDetail.askNumber);
		retXmlWriter.writeElementString("OriOppOrderNo", p_retDetail.oriOppOrderNo);
		retXmlWriter.writeElementString("RefundNo", p_retDetail.refundNo);
		retXmlWriter.writeElementString("RecAct", p_retDetail.recAct);
		retXmlWriter.writeElementString("RecName", p_retDetail.recName);
		retXmlWriter.writeElementString("PayAmount", p_retDetail.payAmount);
		retXmlWriter.writeElementString("Memo", p_retDetail.memo);
		retXmlWriter.writeElementString("Result", p_retDetail.result);
		retXmlWriter.writeElementString("PayInfoCode", p_retDetail.payInfoCode);
		retXmlWriter.writeEndElement();
	}

	private boolean hasWrittenBefore = false;
	public void writeBeforeDetail() throws Exception {
		if (hasWrittenBefore) {
			throw new Exception("writeBeforeDetail已被调用过");
		}
		writeStart();
		retXmlWriter.writeElementString("RespCode", respCode);
		retXmlWriter.writeElementString("RespInfo", respInfo);
		retXmlWriter.writeElementString("ReqSeqID", reqSeqID);
		retXmlWriter.writeElementString("TransState", transState);
		retXmlWriter.writeElementString("PayInfoCode", payInfoCode);
		hasWrittenBefore = true;
	}

	public void writeAfterDetail() throws Exception {
		if (!hasWrittenBefore) {
			writeBeforeDetail();
		}
		writeEnd();
	}
}
